package org.sippr.service.impl;


import org.sippr.mapper.ServerMapper;
import org.sippr.pojo.Server;
import org.sippr.service.ServerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ServerImpl implements ServerService {

    @Autowired
    ServerMapper serverMapper;

    @Override
    public void add(Server value) {
        serverMapper.insert(value);
    }

    @Override
    public Server findByUrl(String address) {
        return serverMapper.findByUrl(address);
    }

    @Override
    public List<Server> list() {
        return serverMapper.list();
    }

    @Override
    public void delete(Integer id) {
        serverMapper.deleteByPrimaryKey(id);
    }

    //1在线，2无法访问，
    @Override
    public List<Server> findOnLineServers() {
        return serverMapper.findByState(1);
    }

    @Override
    public void setServerNotOnLine(Integer id) {
        Server server = new Server();
        server.setId(id);
        server.setState((short) 2);
        serverMapper.updateByPrimaryKeySelective(server);
    }

    @Override
    public void setServiceOnLine(Integer id) {
        Server server = new Server();
        server.setId(id);
        server.setState((short) 1);
        serverMapper.updateByPrimaryKeySelective(server);

    }
}
